<template>
  <el-table :height="calTableHeight() - 50" ref="TableRef" :data="data">
    <el-table-column type="index" :label="$t('序号')" width="60" align="center" />
    <el-table-column show-overflow-tooltip :label="$t('类型')" align="center" prop="type">
      <template slot-scope="{ row }">
        {{ row.type == 1 ? $t('单品') : $t('组合') }}
      </template>
    </el-table-column>

    <el-table-column show-overflow-tooltip :label="$t('sku')" align="center" prop="skuNo" />
    <el-table-column show-overflow-tooltip :label="$t('组合名')" align="center" prop="combinationName" />
    <el-table-column :label="$t('图片')" align="center" prop="type">
      <template slot-scope="{ row }">
        <el-image
          style="width: 50px; height: 50px"
          fit="contain"
          :key="Math.random()"
          v-hover="row.skuImgUrl || row.combinationImgUrl"
          :src="(row.skuImgUrl || row.combinationImgUrl) + '?x-oss-process=image/resize,w_100/quality,q_70'"
        />
      </template>
    </el-table-column>

    <el-table-column show-overflow-tooltip :label="$t('申请数量')" align="center" prop="num" />
    <el-table-column show-overflow-tooltip :label="$t('单价')" align="center" prop="unitPrice">
      <template slot-scope="{ row }">
        {{ row.unitPrice ? (+row.unitPrice).toFixed() : '' }}
      </template>
    </el-table-column>
    <el-table-column show-overflow-tooltip :label="$t('总价')" align="center" prop="totalPrice">
      <template slot-scope="{ row }">
        {{ row.totalPrice ? (+row.totalPrice).toFixed() : '' }}
      </template>
    </el-table-column>
    <el-table-column show-overflow-tooltip :label="$t('申请时间')" align="center" prop="createTime" />
  </el-table>
</template>
<script>
import handleTableSum from '@/utils/handleSum'

export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  props: {
    /**
     * data
     */
    data: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {}
  },
  mounted() {
    // console.log(`this.data ==>`, this.data)
  },
  methods: {
    handleSum(param) {
      /**
       * 需要进行统计的字段
       */
      const data = handleTableSum(param, [])
      console.log(`data ==>`, JSON.parse(JSON.stringify(data)))
      return data
    },

    cancel() {
      this.$emit('update:show', false)
    },
  },
}
</script>
